/**
 * 
 */
package br.com.ema.maze.character.strategy;

import br.com.ema.maze.agents.MazeCharacter;
import br.com.ema.maze.components.MazeSpace;

/**
 * @author Emanuel Cruz Rodrigues -> emanuelcruzrodrigues@gmail.com
 *
 */
public class GreedyStrategy implements MazeCharacterStrategy{

	/* (non-Javadoc)
	 * @see br.com.ema.maze.character.strategy.MazeCharacterStrategy#executeStrategy(br.com.ema.maze.agents.MazeCharacter)
	 */
	@Override
	public void executeStrategy(MazeCharacter mazeCharacter) {
		/*
		 * get the destination and the actual space
		 */
		MazeSpace destination = mazeCharacter.getDestination();
		MazeSpace actualSpace = mazeCharacter.getActualSpace();
		
		/*
		 * calculates the next step
		 */
		
		MazeSpace newSpace = actualSpace.getMinRoute(destination);
		
		/*
		 * update the actual step
		 */
		actualSpace.removeCharacter(mazeCharacter);
		
		/*
		 * setup the new step
		 */
		mazeCharacter.setActualSpace(newSpace);
		if (newSpace != null){
			newSpace.putCharacter(mazeCharacter);
		}
	}

}
